<script type="text/javascript">
	var url;
	function editOrderCar(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$('#dlg').dialog('open').dialog('setTitle','用车费用结算处理');
			$('#fm').form('load',row);
			url = '<?php echo url('ordercar','checkout')?>&id='+row.id;
		}
	}
	
	function saveOrderCar(){
		$('#fm').form('submit',{
			url: url,
			onSubmit: function(){
				return $(this).form('validate');
			},
			success: function(result){
				var result = eval('('+result+')');
				if (result.success){
					$('#dlg').dialog('close');		// close the dialog
					$('#dg').datagrid('reload');	// reload the user data
				} else {
					$.messager.show({
						title: '错误',
						msg: result.msg
					});
				}
			}
		});
	}
	
	$(function(){
		$('#dg').datagrid({
			view: detailview,
			detailFormatter:function(index,row){
				return '<div class="ddv"><table>' +
				'<tr><td style="border:0; padding:2px 8px;">随行人员: </td>' +
				'<td style="border:0; padding:2px 8px;">' + row.colleague + '</td></tr>' +
				'<tr><td style="border:0; padding:2px 8px;">用车事由: </td>' +
				'<td style="border:0; padding:2px 8px;">' + row.description + '</td></tr>' +
				'<tr><td style="border:0; padding:2px 8px;">备注: </td>' +
				'<td style="border:0; padding:2px 8px;">' + row.comment + '</td></tr>' +
				'</table></div>';
			},
		});
	});
	
	function doSearchDate(){   
		$('#dg').datagrid('load',{   
			date1: $('#dd1').datebox("getValue"),   
			date2: $('#dd2').datebox("getValue")
		}); 
	}
	
	function doSearchNum(){
		$('#dg').datagrid('load',{
			num: $('#num').val()
		});
	}
</script>

<table id="dg" title="用车费用结算" class="easyui-datagrid"
		url="<?php echo url('ordercar','list')?>"
		toolbar="#toolbar" pagination="true"
		rownumbers="true" fitColumns="true" fit="true" singleSelect="true">
	<thead>
		<tr>
			<th field="num" width="50">编号</th>
			<th field="date" width="50">日期</th>
			<th field="uname" width="50">用车人</th>
			<th field="driver" width="50">车主</th>
			<th field="car_id" width="50">车牌号</th>
			<th field="destination" width="50">去向</th>
			<th field="amount_estimated" width="50">预估价</th>
			<th field="amount_real" width="50">实际价</th>
			<th field="is_paid" width="50">是否结算</th>
		</tr>
	</thead>
</table>
<div id="toolbar" style="padding:5px;height:auto">
	<div style="margin-bottom:5px">
		<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editOrderCar()">结算处理</a>
	</div>
	<div>
		<label>按单据编号：</label><input id="num" />
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearchNum()">搜索</a>
	</div>
	<div>
		<label>按日期范围：</label><input id="dd1" name="dd1" class="easyui-datebox" /><label>至</label><input id="dd2" name="dd2" class="easyui-datebox" />
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearchDate()">搜索</a>
	</div>
</div>

<div id="dlg" class="easyui-dialog" style="width:400px;height:480px;padding:10px 20px"
		closed="true" buttons="#dlg-buttons">
	<div class="ftitle">用车单信息</div>
	<form id="fm" method="post" novalidate>
		<div class="fitem">
			<label>用车人:</label>
			<input name="uname" readonly>
		</div>
		<div class="fitem">
			<label>车主:</label>
			<input name="driver" readonly>
		</div>
		<div class="fitem">
			<label>车牌号:</label>
			<input name="car_id" readonly>
		</div>
		<div class="fitem">
			<label>去向:</label>
			<input name="destination" readonly>
		</div>
		<div class="fitem">
			<label>预估价:</label>
			<input name="amount_estimated" readonly>
		</div>
		<div class="fitem">
			<label>实际价:</label>
			<input name="amount_real" class="easyui-validatebox" required="true">
		</div>
		<div class="fitem">
			<label>是否结算:</label>
			<input name="is_paid" type="checkbox" value="1">
		</div>
	</form>
</div>
<div id="dlg-buttons">
	<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveOrderCar()">保存</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>